package cn.stylefeng.guns.modular.mallIndexConfig.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.ConfigIndex;
import cn.stylefeng.guns.modular.mallIndexConfig.service.IConfigIndexService;

/**
 * 首页配置控制器
 *
 * @author fengshuonan
 * @Date 2020-06-02 21:04:10
 */
@Controller
@RequestMapping("/configIndex")
public class ConfigIndexController extends BaseController {

    private String PREFIX = "/mallIndexConfig/configIndex/";

    @Autowired
    private IConfigIndexService configIndexService;

    /**
     * 跳转到首页配置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "configIndex.html";
    }

    /**
     * 跳转到添加首页配置
     */
    @RequestMapping("/configIndex_add")
    public String configIndexAdd() {
        return PREFIX + "configIndex_add.html";
    }

    /**
     * 跳转到修改首页配置
     */
    @RequestMapping("/configIndex_update/{configIndexId}")
    public String configIndexUpdate(@PathVariable Integer configIndexId, Model model) {
        ConfigIndex configIndex = configIndexService.selectById(configIndexId);
        model.addAttribute("item",configIndex);
        LogObjectHolder.me().set(configIndex);
        return PREFIX + "configIndex_edit.html";
    }

    /**
     * 获取首页配置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return configIndexService.selectList(null);
    }

    /**
     * 新增首页配置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ConfigIndex configIndex) {
        configIndex.setId(0);
        configIndexService.insert(configIndex);
        return SUCCESS_TIP;
    }

    /**
     * 删除首页配置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer configIndexId) {
        configIndexService.deleteById(configIndexId);
        return SUCCESS_TIP;
    }

    /**
     * 修改首页配置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ConfigIndex configIndex) {
        configIndexService.updateById(configIndex);
        return SUCCESS_TIP;
    }

    /**
     * 首页配置详情
     */
    @RequestMapping(value = "/detail/{configIndexId}")
    @ResponseBody
    public Object detail(@PathVariable("configIndexId") Integer configIndexId) {
        return configIndexService.selectById(configIndexId);
    }
}
